
// Copyright (C) 2011-2012 Luca Piccioni
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//  
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//  
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Diagnostics;

namespace Derm.Render
{
	/// <summary>
	/// Attribute assigned to those types having a direct representation in buffer.
	/// </summary>
	/// <remarks>
	/// <para>
	/// This Attribute is required for detecting an OpenGL sub-array inside a buffer object. All those
	/// types not specifying this Attribute cannot be used for managing buffer object data.
	/// </para>
	/// </remarks>
	[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)]
	[DebuggerDisplay("ArrayBufferItemAttribute ArrayType={ArrayType} ArraySize{ArraySize} Normalized{Normalized}")]
	public class ArrayBufferItemAttribute : Attribute
	{
		/// <summary>
		/// 
		/// </summary>
		/// <param name="arrayType"></param>
		/// <param name="arrayLength"></param>
		public ArrayBufferItemAttribute(VertexBaseType arrayType, uint arrayLength)
		{
			mArrayType = arrayType;
			mArrayLength = arrayLength;
			mArrayRank = 1;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="vertexArrayType"></param>
		public ArrayBufferItemAttribute(VertexArrayType vertexArrayType)
		{
			mArrayType = ArrayBufferItem.GetArrayBaseType(vertexArrayType);
			mArrayLength = ArrayBufferItem.GetArrayLength(vertexArrayType);
			mArrayRank = ArrayBufferItem.GetArrayRank(vertexArrayType);
		}

		/// <summary>
		/// The array type.
		/// </summary>
		public VertexArrayType ArrayType { get { return (ArrayBufferItem.GetArrayType(mArrayType, ArrayLength, ArrayRank)); } }

		/// <summary>
		/// The array base type.
		/// </summary>
		public VertexBaseType ArrayBaseType { get { return (mArrayType); } }

		/// <summary>
		/// The array length.
		/// </summary>
		public uint ArrayLength { get { return (mArrayLength); } }

		/// <summary>
		/// The array rank.
		/// </summary>
		public uint ArrayRank { get { return (mArrayRank); } }

		/// <summary>
		/// Indicates whether the integer data shall be interpreted as normalized floating-point.
		/// </summary>
		public bool Normalized;

		/// <summary>
		/// The array type.
		/// </summary>
		private readonly VertexBaseType mArrayType;

		/// <summary>
		/// The array length.
		/// </summary>
		private readonly uint mArrayLength;

		/// <summary>
		/// The array rank.
		/// </summary>
		private readonly uint mArrayRank;
	}
}